<template>
  <div class="list">
    <!-- <div class="pager-title">{{$route.meta.title}}</div> -->
    <el-form size="small" :inline="true" :model="whereData" class="search-from">
      <el-form-item>
        <el-input @keyup.enter.native="init()" clearable v-model="whereData.title" placeholder="用户账号"></el-input>
      </el-form-item>
      <!-- <el-form-item>
        <el-input @keyup.enter.native="fetchData()" clearable v-model="whereData.phone" placeholder="联系方式"></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="init()">查询</el-button>
        <el-button type="danger" @click="navigateTo('/tasks/create')">发布任务</el-button>
      </el-form-item>
    </el-form>
    <div class="section">
      <el-table
        :data="tableData"
        v-loading="isLoading"
        style="width: 100%">
        <el-table-column
          align="center"
          prop="id"
          label="ID">
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="member_info.real_name"
          label="用户姓名">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="task_info.title"
          label="任务名称">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="task_time"
          label="任务期限">
          <template slot-scope="scope">
            <span v-if="scope.row.task_info.settle_type === 1">长期</span>
            <span v-else-if="scope.row.task_info.settle_type === 2">时间段</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="is_default"
          label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.status === 1">已审核</span>
            <span v-else  style="color: #F56C6C">待审核</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="created_at"
          label="发布时间">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="opera"
          label="操作">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status !== 1" size="mini" type="danger" @click="check(scope.row.id)">审核</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import { mapGetters } from 'vuex'
  import { Message } from 'element-ui'
  export default {
    name: 'list',
    data() {
      return {
        whereData: {
          title: '',
        },
        isLoading:false,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        tableData: [],
      }
    },
    computed:{
      ...mapGetters([
        'userInfo'
      ])
    },
    mounted() {
      this.init()
    },
    methods: {
      navigateTo(url) {
        this.$router.push(url)
      },
      init() {
        this.$http.get('/company/task/acceptlist',{
          'title': this.whereData.title,
          'page': this.pageIndex,
          'limit': this.pageSize
        }).then(res => {
          if (res.code === 0) {
            this.tableData = res.page.list
            this.totalPage = res.page.totalCount
            this.amountData = res.amount
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.init()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.init()
      },
      check(id) {
        this.$http.post(`/company/task/check/${id}`, {}).then((res) => {
          if (res && res.code === 0) {
            Message({
              message: '审核成功',
              center: true,
              type: 'success'
            })
            this.init()
          }
        }).catch((error) => {
        })
      }
    }
  }
</script>
<style lang="less" scoped>
  .uploader {
    display: inline-block;
    margin-left: 10px;
  }
</style>
